﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using Common;

namespace CNCSoft.ErpApps.TMS.longACSS
{
    public partial class frmPayrollReport : Form
    {
        public frmPayrollReport()
        {
            InitializeComponent();
        }

        private void frmPayrollReport_Load(object sender, EventArgs e)
        {

        }

        private void btn_Xem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Validation())
                {
                    PrintData("myrpt_PayrollReport", Convert.ToInt32(txt_Thang.EditValue.ToString()), Convert.ToInt32(txt_Nam.EditValue.ToString()));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        #region "Coding"
        private void PrintData(string namereport, int thang, int nam)
        {
            try
            {
                btn_Xem.Enabled = false;
                //Load Report
                ReportDocument rpt = new ReportDocument();
                if (GlobalVariable.WSInfo.CompanyID.ToLower() == "english")
                    rpt.Load(Application.StartupPath + "\\Report\\" + namereport + ".rpt");
                //Set Connection
                PublicFunction.SetDBLogonForReport(rpt);
                //Set parameters
                PublicFunction.SetParameter(rpt, "@month", thang);
                PublicFunction.SetParameter(rpt, "@year", nam);
                //View report
                frmPrintPreview view = new frmPrintPreview(rpt);
                view.ShowDialog();
                view.Dispose();
                rpt.Dispose();
                btn_Xem.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private bool Validation()
        {
            try
            {
                if (txt_Thang.Text == "")
                {
                    MessageBox.Show("Bạn chưa chọn tháng!");
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
        #endregion
    }
}
